home *** CD-ROM | disk | FTP | other *** search
- /*
- TinyEdit - Minimal TransEdit Demonstration.
-
- The project should include TinyEdit.c (this file), TransEdit.c,
- FakeAlert.c, TransSkel.c (or a project made from TransSkel.c)
- and MacTraps.
-
- 8 November 1986 Paul DuBois
- */
-
- # include <MenuMgr.h>
- # include <FontMgr.h>
- # include "TransEdit.h"
-
-
- # define aboutAlrt 1000 /* "About..." alert number */
-
-
- typedef enum /* File menu item numbers */
- {
- new = 1, /* begin new window */
- open, /* open existing file */
- close, /* close window */
- /* --- */
- quit = 5
- };
-
-
- typedef enum /* Edit menu item numbers */
- {
- undo = 1,
- /* --- */
- cut = 3,
- copy,
- paste,
- clear
- };
-
-
- WindowPtr lastFront = nil; /* keeps track of front window */
- WindowPtr editWind = nil; /* non-nil if edit window open */
- MenuHandle fileMenu;
- MenuHandle editMenu;
-
-
-
- /*
- Set File/Edit menu items according to type of front window.
-
- The general behavior is:
-
- New and Open enabled if an edit window is not open, otherwise they
- are disabled.
-
- Close enabled when an edit or DA window is in front (i.e.,
- when there's a window at all).
-
- Undo disabled when the edit window is in front.
- */
-
- SetMenus ()
- {
- DisableItem (fileMenu, close); /* assume no window at all */
- EnableItem (editMenu, undo);
-
- if (FrontWindow () != nil)
- {
- EnableItem (fileMenu, close);
- if (IsEWindow (FrontWindow ())) /* the edit window's in front */
- DisableItem (editMenu, undo);
- }
-
- if (editWind == nil)
- {
- EnableItem (fileMenu, new);
- EnableItem (fileMenu, open);
- }
- else
- {
- DisableItem (fileMenu, new);
- DisableItem (fileMenu, open);
- }
- }
-
-
- /*
- Got an activate or deactivate. It doesn't matter which, really.
- Set the text menus appropriately for the front window, and draw
- the menu bar, as these menus might change state from enabled to
- disabled or vice-versa.
- */
-
- Activate (active)
- Boolean active;
- {
- SetMenus ();
- }
-
-
- /*
- Close selected from File menu, or close box of edit window was
- clicked.
- */
-
- Close ()
- {
- if (EWindowClose (editWind))
- editWind = nil;
- SetMenus ();
- }
-
-
- /*
- Make a new edit window. Set the title to "Untitled" if not bound
- to file, so that the window titling works the same whether
- TransEdit is compiled in single or multiple window mode.
- */
-
- MakeWind (bindToFile)
- Boolean bindToFile;
- {
- Rect r;
-
- SetRect (&r, 4, 45, 504, 335);
- editWind = NewEWindow (&r, nil, false, -1L, true, 0L, bindToFile);
- if (editWind != nil)
- {
- if (!bindToFile)
- SetWTitle (editWind, "\pUntitled");
- ShowWindow (editWind);
- }
- }
-
-
- /*
- File menu handler
- */
-
- DoFileMenu (item)
- int item;
- {
- WindowPtr theWind;
-
- theWind = FrontWindow ();
- switch (item)
- {
-
- case new:
- MakeWind (false);
- break;
-
- case open:
- MakeWind (true);
- break;
-
- case close:
- if (IsEWindow (theWind))
- Close ();
- else /* DA in front */
- CloseDeskAcc (((WindowPeek) theWind)->windowKind);
- break;
-
- case quit:
- if (ClobberEWindows () == true)
- SkelWhoa ();
- break;
-
- }
- SetMenus ();
- }
-
-
- /*
- Handle selection of About… item from Apple menu
- */
-
- DoAbout ()
- {
- (void) Alert (aboutAlrt, nil);
- }
-
-
- /*
- Background procedure. Check front window, reset menus if it
- changes.
- */
-
- CheckFront ()
- {
- if (FrontWindow () != lastFront)
- {
- SetMenus ();
- lastFront = FrontWindow ();
- }
- }
-
-
- main ()
- {
-
- /*
- Initialize TransSkel, create menus and install handlers.
- */
-
- SkelInit ();
-
- SkelApple ("\pAbout TinyEdit…", DoAbout);
-
- fileMenu = NewMenu (1000, "\pFile");
- AppendMenu (fileMenu, "\pNew/N;Open.../O;(Close/K;(-;Quit/Q");
- SkelMenu (fileMenu, DoFileMenu, nil);
-
- editMenu = NewMenu (1001, "\pEdit");
- AppendMenu (editMenu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
- SkelMenu (editMenu, EWindowEditOp, nil);
-
- /*
- Do TransEdit-specific setup: set creator for any files created,
- set default event notification procedures for new windows.
- */
-
- SetEWindowProcs (nil, nil, Activate, Close);
-
- /*
- Process events until user quits,
- then clean up and exit
- */
-
- SkelBackground (CheckFront);
- SkelMain ();
- SkelClobber ();
- }
-